package com.bw.service.impl;
import java.util.ArrayList;
import java.util.List;

import com.bw.mapper.TbHuodongMapper;
import com.bw.pojo.*;
import com.bw.serivce.YuyueService;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.bw.mapper.TbYuyueMapper;


/**
 * 服务实现层
 * @author Administrator
 *
 */
@Service
public class YuyueServiceImpl implements YuyueService {

	@Autowired
	private TbYuyueMapper yuyueMapper;
	@Autowired
	private TbHuodongMapper huodongMapper;
	/**
	 * 查询全部
	 */
	@Override
	public List<TbYuyue> findAll() {
		return yuyueMapper.selectByExample(null);
	}

	/**
	 * 按分页查询
	 */
	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);		
		Page<TbYuyue> page=   (Page<TbYuyue>) yuyueMapper.selectByExample(null);
		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 增加
	 */
	@Override
	public void add(TbYuyue yuyue) {
		yuyueMapper.insert(yuyue);		
	}

	
	/**
	 * 修改
	 */
	@Override
	public void update(TbYuyue yuyue){
		yuyueMapper.updateByPrimaryKey(yuyue);
	}	
	
	/**
	 * 根据ID获取实体
	 * @param id
	 * @return
	 */
	@Override
	public TbYuyue findOne(Long id){
		return yuyueMapper.selectByPrimaryKey(id);
	}

	/**
	 * 批量删除
	 */
	@Override
	public void delete(Long[] ids) {
		for(Long id:ids){
			yuyueMapper.deleteByPrimaryKey(id);
		}
	}


		@Override
	public PageResult findPage(Yuyue yuyue, int pageNum, int pageSize) {
		List<Yuyue> list = 	yuyueMapper.findAll(yuyue);
		return new PageResult(list.size(), list);
	}
	
}
